package o;

import android.content.Context;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class ckl extends ClickableSpan {
    private Context ˊ;
    private d ˋ;
    private boolean ˏ;

    public interface d {
        void ˊ();
    }

    public static class c extends LinkMovementMethod {
        private ckl ˋ;

        public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent motionEvent) {
            if (motionEvent.getAction() == 0) {
                this.ˋ = ˋ(textView, spannable, motionEvent);
                if (this.ˋ != null) {
                    this.ˋ.ˎ(true);
                    Selection.setSelection(spannable, spannable.getSpanStart(this.ˋ), spannable.getSpanEnd(this.ˋ));
                }
            } else if (2 == motionEvent.getAction()) {
                ckl ˋ = ˋ(textView, spannable, motionEvent);
                if (!(this.ˋ == null || ˋ == this.ˋ)) {
                    this.ˋ.ˎ(false);
                    this.ˋ = null;
                    Selection.removeSelection(spannable);
                }
            } else {
                Selection.removeSelection(spannable);
                if (this.ˋ == null) {
                    return true;
                }
                this.ˋ.ˎ(false);
                this.ˋ = null;
            }
            return super.onTouchEvent(textView, spannable, motionEvent);
        }

        private ckl ˋ(TextView textView, Spannable spannable, MotionEvent motionEvent) {
            int x = (((int) motionEvent.getX()) - textView.getTotalPaddingLeft()) + textView.getScrollX();
            int y = (((int) motionEvent.getY()) - textView.getTotalPaddingTop()) + textView.getScrollY();
            Layout layout = textView.getLayout();
            x = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x);
            ckl[] o_cklArr = (ckl[]) spannable.getSpans(x, x, ckl.class);
            if (o_cklArr.length > 0) {
                return o_cklArr[0];
            }
            return null;
        }
    }

    public ckl(Context context) {
        this.ˊ = context;
    }

    public void onClick(View view) {
        if (this.ˋ != null) {
            this.ˋ.ˊ();
        }
    }

    public void ˏ(d dVar) {
        this.ˋ = dVar;
    }

    public void updateDrawState(TextPaint textPaint) {
        if (textPaint != null) {
            int color;
            super.updateDrawState(textPaint);
            textPaint.setColor(this.ˊ.getResources().getColor(o.dky.d.ˊ));
            if (this.ˏ) {
                color = this.ˊ.getResources().getColor(o.dky.d.ʽ);
            } else {
                color = this.ˊ.getResources().getColor(o.dky.d.ˊᐝ);
            }
            textPaint.bgColor = color;
            textPaint.setUnderlineText(false);
        }
    }

    public void ˎ(boolean z) {
        this.ˏ = z;
    }
}
